package org.boulderfoodrescue.webapp.client.old.tests;

import org.boulderfoodrescue.webapp.client.googlemap.GoogleMap;
import org.boulderfoodrescue.webapp.test.TestResult;

import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.view.client.ListDataProvider;

public class TestsCellTable extends FlowPanel{
  protected CellTable<TestResult> table;
  protected ListDataProvider<TestResult> dataProvider;
  protected GoogleMap gMap;
  public TestsCellTable(){
    dataProvider = new ListDataProvider<TestResult>();
    table = new CellTable<TestResult>();
    
    TextColumn<TestResult> nameColumn = new TextColumn<TestResult>(){
      @Override
      public String getValue(TestResult object) {
        return object.getTestPackage();
      }
    };
    
    TextColumn<TestResult> statusColumn = new TextColumn<TestResult>(){
      @Override
      public String getValue(TestResult object) {
        if(object.getSuccess() == null)
          return "running";
        else if(object.getSuccess())
          return "Passed";
        return "Failed";
      }
    };
    
    TextColumn<TestResult> messageColumn = new TextColumn<TestResult>(){
      @Override
      public String getValue(TestResult object) {
        if(object.getTestMessage() == null)
          return "N/A";
        return object.getTestMessage();
      }
    };
    

    table.addColumn(nameColumn, "Name");
    table.addColumn(statusColumn, "Status");
    table.addColumn(messageColumn, "Message");
    
    dataProvider.addDataDisplay(table);
    
    this.add(table);
  }
  public void addTestResult(TestResult new_place){
    dataProvider.getList().add(new_place);
  }
  public void removeTestResult(TestResult place){
    dataProvider.getList().remove(place);
  }
  public void clearTable(){
    dataProvider.getList().clear();
  }
  public void redrawTable(){
    table.redraw();
  }
}
